import {
  request
} from "../../request/index.js"
import regeneratorRuntime from "../../lib/runtime/runtime.js"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    timeId: -1,
    //取消按钮是否显示
    isFocus:false,
    inpValue:""
  },
  onLoad: function (options) {

  },
  onShow: function () {

  },
  handleInput(e) {
    //获取输入框的值
    const {
      value
    } = e.detail;
    //检测合法性
    if (!value.trim()) {
      //值不合法
      this.setData({
        isFocus:false
      })
      return;
    }
    //检验通过，把用户输入的值发送到后台  发送请求
    this.setData({
      isFocus:true
    })
    clearTimeout(this.timeId);
    this.timeId = setTimeout(() => {
      this.qsearch(value)
    },1000)
  },
  async qsearch(query) {
    const res = await request({
      url: "/goods/qsearch",
      data: {
        query
      }
    })
    console.log(res);
  },
  handleCancle(){
    this.setData({
      inpValue:""
    })
  }
})